package com.req;

import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.BufferedReader;
import java.io.IOException;
import java.util.stream.Stream;


@WebServlet(urlPatterns = "/req2",name = "req2")
public class request2 extends HttpServlet {

    /**
     * 获取 请求体中的数据（ 只有 post 提交的方式，才会有请求体 ）
     * @param req
     * @param resp
     * @throws ServletException
     * @throws IOException
     */
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        // 获取到请求体中的数据
        BufferedReader reqReader = req.getReader();
        Stream<String> lines = reqReader.lines();
        lines.forEach(System.out::println);

//        //根据名字 获取 参数值
//        final String username = request.getParameter("username");
//        System.out.println( username );
//
//        //如果有多个 ： 复选框
//        final String[] hobbies = request.getParameterValues("hobbies");
//        System.out.println(Arrays.toString( hobbies ));
    }
}
